<!-- 
    判断一个字符串'abcoefoxyozzopp'中出现次数最多的字符，并统计其次数
 -->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var str = 'abcoefoxyozzopp';
        var o = {};
        for (var i = 0; i < str.length; i++) {
            var chars = str.charAt(i)  //chars是字符串中每一个字符
            if (o[chars]) {
                o[chars]++;

            } else {
                o[chars] = 1;
            }

        }
        console.log(o);

        var max = 0;
        var ch = '';
        //遍历对象
        for (k in o) {
            //k是属性名   o[k]得到的是属性值
            if (o[k] > max) {
                max = o[k];
                ch = k;
            }

        }
        console.log('最多的字符' + ch);
        console.log(max);

    </script>
</head>

<body>

</body>

</html>